<!DOCTYPE html>
<html>
<meta charset="utf-8"> 
<head>
	<title data-localize="cache.title">缓存机</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
<style type="text/css">
p{
	margin: 0;
}
.u-line{
	margin: 0 auto;
	width: 650px;
    height: 800px;
    overflow: hidden;
}
.u-road{
	position: relative;
	height: 200px;
	width: 770px;
	float: right;
	margin-top: 110px;
	-webkit-transform: rotateY(180deg);
}
.u-road p{
	-webkit-transform: rotateY(180deg);
}
.u-road span{
	display: inline-block;
	-webkit-transform: rotateY(180deg);
}
.u-roadcon{
	position: relative;
	float: left;
}
.u-roadcon:after{
	content: '';
	display: block;
	clear: both;
}
.u-road:after{
	content: '';
	display: block;
	clear: both;
}
.u-road-opposite:after{
	content: '';
	display: block;
	clear: both;
}
.u-track{
	position: absolute;
	height: 28px;
	width: 100%;
	left: 0;
	top: 85px;
	border-top: 1px solid #cecece;
	border-bottom: 1px solid #cecece;
}
.u-outtrack{
	position: absolute;
	height: 52px;
	width: 28px;
	left: 550px;
	top: 33px;
	border-left: 1px solid #cecece;
	border-right: 1px solid #cecece;
}
.break{
	background: url('image/break.png') no-repeat 0 0;
	background-size: 100% 100%;
}
.u-btns{
	margin: 20px 0 0 60%;
}
.u-input{
	position: absolute;
	left: 650px;
	top: 65px;
	width: 68px;
	height: 68px;
	background: #b9b9b9;
	border-radius: 4px;
	border: 1px solid #29abe2;
	z-index: 10;
	text-align: center;
	line-height: 68px;
}
.u-output{
	position: absolute;
	left: 530px;
	top: -35px;
	width: 68px;
	height: 68px;
	background: #eef2f7;
	border-radius: 4px;
	border: 1px solid #29abe2;
	z-index: 2;
	text-align: center;
	line-height: 68px;
}
.u-cache{
	position: absolute;
	left: 170px;
	top: -35px;
	width: 68px;
	height: 68px;
	background: #bdcee2;
	border-radius: 4px;
	border: 1px solid #29abe2;
	z-index: 10;
}
.u-cache p{
	margin: 0;
	text-align: center;
	font-size: 10px;
	margin-top: 4px;
}
.u-hand{
	position: absolute;
	width: 24px;
	height: 24px;
	top: -10px;
	left: -10px;
	border-radius: 50%; 
	background: #9acfe1;
	border: 1px solid #eee;
	z-index: -1;
}
.u-hand:after{
	content: '';
	display: block;
	width: 12px;
	height: 12px;
	margin: 0 auto;
	margin-top: 6px;
	border-radius: 6px; 
	background: #66bfdd;
}
.u-handbar{
	position: relative;
	float: left;
	width: 6px;
	height: 6px;
	margin-top: 31px;
	margin-left: 31px;
	border-radius: 4px; 
	background: #66bfdd;
	opacity: 0;
}
/*animations*/

.stop {
    animation-play-state: paused;
}
.opposite{
	-webkit-transform: rotateY(180deg);
}
.u-road.opposite{
	float: right;
}
.opposite{
	margin-top: 0;
	-webkit-transform: rotateX(180deg) rotateY(180deg);
	display: none;
}
.opposite p{
	-webkit-transform: rotateX(180deg) rotateY(180deg);
}
.opposite span{
	display: inline-block;
	-webkit-transform: rotateX(180deg) rotateY(180deg);
}
.u-adjust{
	position: absolute;
	left: 290px;
	width: 71px;
	height: 20px;
}
#u-boxe{
	position: absolute;
	opacity: 0;
}
</style>
</head>
<body>
<div class='u-head'>
   <div class="u-headcon">
	<a href="index.html"><div class="u-mainpage" data-localize="back">回到首页</div></a>
	<h3 data-localize="cache.title">缓存机</h3>
	<div class="changeLang">
		<p class="u-lang"><span>中文</span><span>English</span></p>
	    <div isopen="true" class="changeLangBtn"></div>
	</div>
</div>
</div>
<div class="u-infos">
	<h2 data-localize="cache.info_title">状态区域</h2>
	<div class="u-errorlist">
		<h3 data-localize="yichang">异常一览：</h3>
		<div class="u-errorlistcon">
		</div>
	</div>
	<p class="status"><span data-localize="cache.running">运行状态：</span><span class="u-cube t-status"></span></p>
</div>
<div class="u-cachecon">
<div class="u-cachelist">
</div>
</div>
<div class="t-con">
<div class="u-line">
<div class="u-boxcon needleft u-boxconspe" id="u-boxe"><div class="u-box u-boxe"></div></div>
	<div class="u-road lineA">
		<div class="u-adjust u-adjusttop"><img src="image/adjust.png" width="100%"></div>
		<div class="u-adjust u-adjustbottom"><img src="image/adjust.png" width="100%"></div>
		<div class="u-track"></div>
		<div class="u-cache"><div class="circle">
			<div class="pie_left"><div class="circle_left"></div></div>
			<div class="pie_right"><div class="circle_right"></div></div>
			<div class="mask"><span class="cachenum">0</span></div>
			</div></div>
		<div class="u-boxcon">
			<div class="u-box u-box5"><p></p></div>
			
		</div>
		<div class="u-boxcon"><div class="u-box u-box4" id="u-box4"><p></p></div><div class="u-handbar" id="u-handbar"><div class="u-hand"></div></div></div>
		<div class="u-boxcon"><div class="u-box u-box3"><p></p></div></div>
		<div class="u-boxcon"><div class="u-box u-box2"><p></p></div></div>
		<div class="u-boxcon"><div class="u-box u-box1"><p></p></div></div>
	</div>
	<div class="u-road opposite lineB">
		<div class="u-adjust u-adjusttop"><img src="image/adjust.png" width="100%"></div>
		<div class="u-adjust u-adjustbottom"><img src="image/adjust.png" width="100%"></div>
		<div class="u-track"></div>
		<div class="u-cache"><div class="circle">
			<div class="pie_left"><div class="circle_left"></div></div>
			<div class="pie_right"><div class="circle_right"></div></div>
			<div class="mask"><span class="cachenum">0</span></div>
			</div></div>
		<div class="u-boxcon">
			<div class="u-box u-box5"><p></p></div>
			
		</div>
		<div class="u-boxcon"><div class="u-box u-box4" id="u-box4-b"><p></p></div><div class="u-handbar" id="u-handbar-b"><div class="u-hand"></div></div></div>
		<div class="u-boxcon"><div class="u-box u-box3"><p></p></div></div>
		<div class="u-boxcon"><div class="u-box u-box2"><p></p></div></div>
		<div class="u-boxcon"><div class="u-box u-box1"><p></p></div></div>
	</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.localize.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/language_cookie.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var lastData = null,
	si=null,
	isFirst = true;
var url = getUrl("cache");
var request = new GetRequest();
var showval= request.type; 
if ('WebSocket' in window) {
    websocket = new WebSocket(url+'/'+request.line+'/'+request.index);
}else {
    alert('Not support websocket')
}
if (request.line == "A") {
	$('.lineB').hide();
	$('.lineA').show();
}else if (request.line == "B") {
	$('.lineA').hide();
	$('.lineB').show();
} 

websocket.onerror = function () {
    $('.u-boxcon').addClass('stop');
	$('.u-handbar1').addClass('stop');
};

websocket.onopen = function (event) {
	$('.u-handbar1').removeClass('stop');
    $('.u-box4').removeClass('stop');
}
websocket.onclose = function () {
    $('.u-boxcon').removeClass('moveleft');
    $('.u-adjust').addClass('stop');
};
function addanimate(obj){
    for (var i = 0,len = obj.length; i < len; i++) {
       (function(i){
            if (obj[i].isPause == 0){
                $('.u-box'+obj[i].stack_index).parent().addClass('moveleft');
            }
            if (obj[i].stack_index == 4) {
            	switch (obj[i].isCache) 
				{ 
				  case 0:
				  	
				  	break; 
				  case 1:
				  	$('.u-handbar').addClass('grow');
					$('.u-box4').addClass('moveup');
				  	break;
				  default:
				  
				  	break;
				}
            }
       })(i); 
    }
}
websocket.onmessage = function (event) {
	$('.u-adjust').removeClass('stop');
	$('#u-boxe').addClass('moveleft');
	si = JSON.parse(event.data.replace(/\bNaN\b/g, "null"));
    if (!lastData) {
    	lastData = si;
    }
    changeColor($('.t-status'),si.p2);
    console.log(si);
	$('.u-box4').show();
	if (isFirst) {
    	count(si.stack_list,showval);
		isFirst = false;
    }
    if (si.isPause1 == 0) {
    	$('.u-adjusttop').addClass('u-adjustup');
    	$('.u-adjustbottom').addClass('u-adjustdown');
    }else if (si.isPause1 == 1) {
    	$('.u-adjusttop').removeClass('u-adjustup');
    	$('.u-adjustbottom').removeClass('u-adjustdown');
    }
    addanimate(si.stack_list);
    errorRender();
	cacheRender();
	drawCircle($('.u-cache'),si.cache_setting_qty,si.cache_current_qty);

    lastData = si;
}

document.getElementById('u-boxe').addEventListener("webkitAnimationIteration", function(){
	reset();
	count(si.stack_list,showval);
    $('.u-boxcon').removeClass('moveleft');
}, false);
document.getElementById('u-box4').addEventListener("webkitAnimationIteration", function(){
    $('.u-box4').removeClass('moveup');
}, false); 
document.getElementById('u-handbar').addEventListener("webkitAnimationIteration", function(){
    $('.u-handbar').removeClass('grow');
}, false);
document.getElementById('u-box4-b').addEventListener("webkitAnimationIteration", function(){
    $('.u-box4').removeClass('moveup');
}, false); 
document.getElementById('u-handbar-b').addEventListener("webkitAnimationIteration", function(){
    $('.u-handbar').removeClass('grow');
}, false);
window.onbeforeunload = function(){
	websocket.close();
}  
</script>
</body>
</html>